﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using System.Linq;
using IB_report_stand.Objects;
using System.Collections.Generic;
using DevExpress.XtraPivotGrid.Data.Wrappers;
using System.Configuration;
using IB_report_stand.DAL;




namespace IB_report_stand
{
    public partial class rpt_sale_diary : DevExpress.XtraReports.UI.XtraReport
    {
        private DateTime _startDate;
        private DateTime _endDate;
        private String _rekNum1;
        private String _rekNum2;
        private String _rekNum3;
        private String _rekNum4;
        private String _rekNum5;
        private String _rekNum6;
        private String _rekNum7;

        private String _account1;
        private String _account2;

        //private DateTime _startDate = new DateTime(2012, 01, 01);
        //private DateTime _endDate = new DateTime(2012, 12, 01);
        //private String _rekNum1 = "150";
        //private String _rekNum2 = "151";
        //private String _rekNum3 = "152";
        //private String _rekNum4 = "153";
        //private String _rekNum5 = "154";
        //private String _rekNum6 = "155";
        //private String _rekNum7 = "156";

        //private String _account1 = "301";
        //private String _account2 = "302";




        public rpt_sale_diary()
        {
            init();
        }

        public rpt_sale_diary(String num1, String num2, String num3, String num4, String num5, String num6, String num7, String acc1, String acc2, DateTime start, DateTime end)
        {
            RekNum1 = num1;
            RekNum2 = num2;
            RekNum3 = num3;
            RekNum4 = num4;
            RekNum5 = num5;
            RekNum6 = num6;
            RekNum7 = num7;
            Account1 = acc1;
            Account2 = acc2;
            StartDate = start;
            EndDate = end;

            init();
        }


        private void init()
        {
            InitializeComponent();
            prepareForReport();

            lblStartDate.Text = StartDate.ToShortDateString();
            lblEndDate.Text = EndDate.ToShortDateString();

            lblCompanyName.Text = ConfigurationManager.AppSettings["companyName"];
            lblCompanyAddress.Text = ConfigurationManager.AppSettings["companyAddress"];
        }

        private void prepareForReport()
        {

            DataObjectsDataContext dataContext = new DataObjectsDataContext();

            var dataReport = from saleJourResult in dataContext.func_sale_jour(_rekNum1, _rekNum2, _rekNum3, _rekNum4, _rekNum5, _rekNum6, _rekNum7, _account1, _account2, _startDate, _endDate)
                             select saleJourResult;

            List<SaleReportObject> lstSource = new List<SaleReportObject>();
            foreach (func_sale_jourResult item in dataReport)
            {
                SaleReportObject obj = new SaleReportObject() { StartDate = _startDate, EndDate = _endDate };

                if (item.datum.HasValue)
                    obj.Datum = item.datum.Value;

                obj.Dagbknr = item.dagbknr;
                obj.Bkstnr = item.bkstnr;
                obj.Descriptions = item.descriptions;


                if (item.GhiCoLedger1.HasValue)
                    obj.GhiCoLedger1 = item.GhiCoLedger1.Value;
                if (item.GhiCoLedger2.HasValue)
                    obj.GhiCoLedger2 = item.GhiCoLedger2.Value;
                if (item.GhiCoLedger3.HasValue)
                    obj.GhiCoLedger3 = item.GhiCoLedger3.Value;


                if (item.LedgerCode.HasValue)
                    obj.LedgerCode = item.LedgerCode.Value;
                if (item.GhiCoLedger2.HasValue)
                    obj.GhiCoKHAC = item.GhiCoKHAC.Value;


                lstSource.Add(obj);
            }

            this.bindingDataSource.DataSource = lstSource;

        }


        public String RekNum1
        {
            get
            {
                return _rekNum1;
            }
            // Assigns to the number data member.
            set
            {
                _rekNum1 = value;
            }
        }

        public String RekNum2
        {
            get
            {
                return _rekNum2;
            }
            // Assigns to the number data member.
            set
            {
                _rekNum2 = value;
            }
        }

        public String RekNum3
        {
            get
            {
                return _rekNum3;
            }
            // Assigns to the number data member.
            set
            {
                _rekNum3 = value;
            }
        }

        public String RekNum4
        {
            get
            {
                return _rekNum4;
            }
            // Assigns to the number data member.
            set
            {
                _rekNum4 = value;
            }
        }

        public String RekNum5
        {
            get
            {
                return _rekNum5;
            }
            // Assigns to the number data member.
            set
            {
                _rekNum5 = value;
            }
        }


        public String RekNum6
        {
            get
            {
                return _rekNum6;
            }
            // Assigns to the number data member.
            set
            {
                _rekNum6 = value;
            }
        }

        public String RekNum7
        {
            get
            {
                return _rekNum7;
            }
            // Assigns to the number data member.
            set
            {
                _rekNum7 = value;
            }
        }

        public String Account1
        {
            get
            {
                return _account1;
            }
            // Assigns to the number data member.
            set
            {
                _account1 = value;
            }
        }

        public String Account2
        {
            get
            {
                return _account2
;
            }
            // Assigns to the number data member.
            set
            {
                _account2 = value;
            }
        }

        public DateTime StartDate
        {
            get
            {
                return _startDate;
                ;
            }
            // Assigns to the number data member.
            set
            {
                _startDate = value;
            }
        }

        public DateTime EndDate
        {
            get
            {
                return _endDate;
                ;
            }
            // Assigns to the number data member.
            set
            {
                _endDate = value;
            }
        }
    }
}
